package utils

import (
	"math"
)

// PagedResponse 分页响应结构体
type PagedResponse struct {
	List      interface{} `json:"list"`
	Page      int         `json:"page"`
	PageSize  int         `json:"page_size"`
	Total     int64       `json:"total"`
	TotalPage int         `json:"total_page"`
}

// NewPagedResponse 创建分页响应
func NewPagedResponse(list interface{}, page, pageSize int, total int64) *PagedResponse {
	totalPage := 0
	if pageSize > 0 {
		totalPage = int(math.Ceil(float64(total) / float64(pageSize)))
	}
	return &PagedResponse{
		List:      list,
		Page:      page,
		PageSize:  pageSize,
		Total:     total,
		TotalPage: totalPage,
	}
}

// GetTotalPage 计算总页数
func GetTotalPage(total int64, pageSize int) int {
	return int(math.Ceil(float64(total) / float64(pageSize)))
}
